﻿using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using System;
using System.Diagnostics;

namespace SmarterCharger.Library.Tests.Unit.Infrastructure
{
    public abstract class TestBase
    {
        protected Exception Exception { get; set; }

        [TestInitialize]
        public void Initialize()
        {
            try
            {
                Arrange();
                Act();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Cleanup();   
                throw;
            }
        }

        [TestCleanup]
        public void Complete()
        {
            Cleanup();
        }

        protected virtual void Arrange()
        {
        }

        protected virtual void Act()
        {
        }
        protected virtual void Cleanup()
        {
        }

        protected void ExpectException(Action act)
        {
            try
            {
                act();
            }
            catch (Exception ex)
            {
                Exception = ex;
            }

            if (Exception == null)
                Assert.Fail("Exception expected");
        }
    }
}